package vip.huhaiong.hlfood.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vip.huhaiong.hlfood.pojo.Rs;
import vip.huhaiong.hlfood.pojo.UserInfo;
import vip.huhaiong.hlfood.service.UserService;

import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    UserService userService;
    @Autowired
    public UserController(UserService userService){
        this.userService = userService;
    }

    @PostMapping("/getShouCang")
    public Rs getShouCang(@RequestBody Map<String,Object> map){
        String openid = (String) map.get("openid");
        return userService.getListByOpenId(openid);
    }

    @GetMapping("/remove")
    public Rs remove(String id){
        return userService.remove(Integer.parseInt(id));
    }

    @PostMapping("/add")
    public Rs add(@RequestBody UserInfo pojo){
        return userService.add(pojo);
    }

    @GetMapping("/getOpenId")
    public Rs getOpenId(String code){
        return userService.getOpenId(code);
    }
}
